<?php

/**
 * 自动生成 WxEventVoteStatController
 * 
 * Apps/Mp/Controller/WxEventVoteStatController.class.php
 * gt_admin @ 2015-09-11
 */

namespace Mp\Controller;

use Common\Service\WxEventVoteStatService;

class WxEventVoteStatController extends MpController {

  public function index() {
    $action = I('get.action', 'read');

    $data = $this->_init_data();
    $data['module_name'] = '{module_name}';
    $data['module_url'] = U( $this->base_path . 'index');

    $WxEventVoteStat = WxEventVoteStatService::instance();
    $data['config'] = array(
      'action' => $action,
      'action_label' => $this->action_label[$action],
      'menu_id'    => $this->menu_id ,
      'module_url' => U($this->base_path . 'index'),
      'read_url'   => U($this->base_path . 'read' ),
      'create_url' => U($this->base_path . 'create'),
      'update_url' => U($this->base_path . 'update'),
      'delete_url' => U($this->base_path . 'delete'),
      'page' => 1,
      'page_size' => C('PAGE_SIZE'),
      'row' => $WxEventVoteStat->get_default_row() 
    );

    $data['param'] = array();

    $this->display_with_layout($data, $this->controller .':index');
  }

  function read() {
    $post = I('post.');

    $config = array(
      'page' => $post['page'],
      'page_size' => $post['page_size'],
      'sort' => empty($post['sort']) ? 'id' : $post['sort'],
      'order' => empty($post['order']) ? 'DESC' : $post['order'],
    );

    $WxEventVoteStat = WxEventVoteStatService::instance();
    $data['rows'] = $WxEventVoteStat->get_by_cond($config);

    $config['count'] = TRUE;
    $data['total'] = $WxEventVoteStat->get_by_cond($config);

    $this->ajaxReturn($data);
  }

  function create() {
    $post = I('post.');
    if (empty($post)) {
      $this->ajaxReturn(ajax_arr('数据错误,请稍后再试'));
    }
    
    $WxEventVoteStat = WxEventVoteStatService::instance();
    $ret = $WxEventVoteStat->create($post);
    $this->ajaxReturn($ret);
  }

  function update($id = 0) {
    $post = I('post.');
    if (empty($post)) {
      $this->ajaxReturn(ajax_arr('数据错误,请稍后再试'));
    }

    $WxEventVoteStat = WxEventVoteStatService::instance();
    $ret = $WxEventVoteStat->update($id, $post);
    $this->ajaxReturn($ret);
  }

  function delete() {
    $ids = I('post.ids');
    $WxEventVoteStat = WxEventVoteStatService::instance();
    $ret = $WxEventVoteStat->delete($ids); 
    $this->ajaxReturn($ret);
  }
}
